/*
 * @Author: your name
 * @Date: 2021-09-19 10:33:55
 * @LastEditTime: 2021-09-19 11:14:04
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \more-money\src\models\RecordsListModel.ts
 */
const localStorageKeyName = 'RecordList';

const RecordsListModel = {
    getList(){
        const res = JSON.parse(window.localStorage.getItem(localStorageKeyName) || '[]');
        // || '[]'是为了当getItem为空时赋予默认值从而解决ts纠错
        return res;
    },
    create(params: RecordItem){
        const res = this.getList();
        res.push(params);
        this.updateList(res);
    },
    updateList(list: RecordItem[]){
        window.localStorage.setItem(localStorageKeyName, JSON.stringify(list));
    }
}

export default RecordsListModel;